﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HR60_PanelSoft.Model;

namespace HR60_PanelSoft.Service 
{
	public class NetService : CommonService
	{
		// 保存
		public static void save(HR60_PanelSoft.Model.Net source, HR60_PanelSoft.Model.Net dto)
		{
			source.name = dto.name;
			source.index = dto.index;
		}
		
		// 添加
		public static void append(HR60_PanelSoft.Model.Net net)
		{
			proj.nets.Add (net);
		}

		// 删除
		public static void remove(HR60_PanelSoft.Model.Net net)
		{
			// 删除下辖的面板
			for (int i=0; i<net.panels.Count; i++)
			{
				PanelService.remove (net.panels [i]);
			}
			proj.nets.Remove (net);
		}


		public static int newNetId()
		{
			for(int id=1; id<512; id++)
			{
				bool findFlag = false;
				for (int i = 0; i < proj.nets.Count; i++)
				{
					if (id == proj.nets[i].index)
					{
						findFlag = true;
						break;
					}
				}
				if (!findFlag) return id;
			}
			return -1;
		}
	}
}
